package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import entity.Course;
import entity.User;
import service.ISmsserivce;
import service.impl.SmsserivceImpl;

/**
 * Servlet implementation class UserSerlvet
 */
@WebServlet(asyncSupported = true, urlPatterns = { "/StudentSerlvet" })
public class StudentSerlvet extends HttpServlet {
	
	ISmsserivce smsservice = new SmsserivceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		
//		String username = request.getParameter("username");
		
		HttpSession session = request.getSession();
		String  username = (String) session.getAttribute("username");
		User user = new User(username);
		
		System.out.println(username);
		try {
			List<Course> selectCourse = smsservice.selectCourse(user);
			System.out.println(selectCourse);
			if(selectCourse !=null) {
			session.setAttribute("selectCourse", selectCourse);
			response.sendRedirect("Studenttable.jsp");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
